package cn.ad.param;

import cn.ad.interceptor.PageParameter;

/**
 * 分页和排序参数抽象类
 * @author Administrator
 */
public class AbstractPagingSortParam implements IPagingParam, ISortParam {
	
	/**
	 * 记录起始位置
	 */
	private int offset; 
	
	/**
	 * 返回记录数
	 */
	private int limit=10;
	
	/**
	 * 排序字段名称
	 */
	private String sortby;
	
	/**
	 * 排序顺序
	 */
	private ORDER order;

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.ISortParam#setSortby(java.lang.String)
	 */
	@Override
	public void setSortby(String fieldName) {
		this.sortby = fieldName;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.ISortParam#getSortby()
	 */
	@Override
	public String getSortby() {
		return sortby;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.ISortParam#setOrder(cn.falconnect.addsp.console.spring.controller.requestparams.ORDER)
	 */
	@Override
	public void setOrder(ORDER order) {
		this.order = order;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.IPagingParam#getOffset()
	 */
	@Override
	public int getOffset() {
		return offset;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.ISortParam#getOrder()
	 */
	@Override
	public ORDER getOrder() {
		return order;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.IPagingParam#setOffset(int)
	 */
	@Override
	public void setOffset(int offset) {
		this.offset = offset;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.IPagingParam#getLimit()
	 */
	@Override
	public int getLimit() {
		return limit;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.addsp.console.spring.controller.requestparams.IPagingParam#setLimit(int)
	 */
	@Override
	public void setLimit(int limit) {
		this.limit = limit;
	}
	
	/**
	 * 获取分页对象
	 * @return
	 */
	public PageParameter getPageInfo(){
		PageParameter page = new PageParameter();
		page.setCurrentPage(this.offset/this.limit+1);
		page.setPageSize(this.limit);
		return page;
	}

}
